package com.blog.controller;

import com.blog.pojo.request.UserLoginRequest;
import com.blog.pojo.response.UserInfoResponse;
import com.blog.pojo.response.UserLoginResponse;
import com.blog.service.BlogService;
import com.blog.service.UserService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource(name = "userServiceImpl")
private UserService userService;
    @Resource(name = "blogServiceImpl")
    private BlogService blogService;

    @RequestMapping("/login")
    public UserLoginResponse login(@RequestBody @Validated UserLoginRequest userLoginRequest){
log.info("用户登录，用户名：{}",userLoginRequest.getUsername());
return userService.checkPassword(userLoginRequest);
    }

    @RequestMapping("/getUserInfo")
public UserInfoResponse getUserInfo(@NotNull(message = "userId不能为空") Integer userId){
        log.info("获取用户信息，用户id：{}",userId);
        return userService.getUserInfo(userId);
    }

    @RequestMapping("/getAuthoInfo")
    public UserInfoResponse getAuthoInfo(@NotNull(message = "blogId不能为空") Integer blogId){
        log.info("获取作者信息,blogId:{}",blogId);
        return userService.getAuthoInfo(blogId);
    }
}
